package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.HealthRecordVo;
import org.dromara.nursing.domain.bo.HealthRecordBo;
import org.dromara.nursing.service.IHealthRecordService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 健康信息管理
 *
 * @author Xue
 * @date 2025-04-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/healthRecord")
public class HealthRecordController extends BaseController {

    private final IHealthRecordService healthRecordService;

    /**
     * 查询健康信息管理列表
     */
    // @SaCheckPermission("nursing:healthRecord:list") // 已移除权限验证
    @GetMapping("/list")
    public TableDataInfo<HealthRecordVo> list(HealthRecordBo bo, PageQuery pageQuery) {
        return healthRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出健康信息管理列表
     */
    // @SaCheckPermission("nursing:healthRecord:export") // 已移除权限验证
    @Log(title = "健康信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HealthRecordBo bo, HttpServletResponse response) {
        List<HealthRecordVo> list = healthRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "健康信息管理", HealthRecordVo.class, response);
    }

    /**
     * 获取健康信息管理详细信息
     *
     * @param recordId 主键
     */
    // @SaCheckPermission("nursing:healthRecord:query") // 已移除权限验证
    @GetMapping("/{recordId}")
    public R<HealthRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long recordId) {
        return R.ok(healthRecordService.queryById(recordId));
    }

    /**
     * 新增健康信息管理
     */
    // @SaCheckPermission("nursing:healthRecord:add") // 已移除权限验证
    @Log(title = "健康信息管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HealthRecordBo bo) {
        return toAjax(healthRecordService.insertByBo(bo));
    }

    /**
     * 修改健康信息管理
     */
    // @SaCheckPermission("nursing:healthRecord:edit") // 已移除权限验证
    @Log(title = "健康信息管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HealthRecordBo bo) {
        return toAjax(healthRecordService.updateByBo(bo));
    }

    /**
     * 删除健康信息管理
     *
     * @param recordIds 主键串
     */
    // @SaCheckPermission("nursing:healthRecord:remove") // 已移除权限验证
    @Log(title = "健康信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] recordIds) {
        return toAjax(healthRecordService.deleteWithValidByIds(List.of(recordIds), true));
    }
}
